package com.hermes.utils.logger;

import org.apache.log4j.Logger;

/**
 * 封装日志打印类
 * @author THINKPAD
 *
 */
public class LoggerUtil {

    /**
     * debug
     * 
     * @param logger
     * @param obj
     */
    public static void debug(Logger logger, Object... obj) {
        if (logger.isDebugEnabled()) {
            logger.debug(getLogString(obj));
        }
    }

    /**
     * error
     */
    public static void error(Logger logger, Object... obj) {
        logger.error("【异常】" + getLogString(obj));
    }

    /**
     * error
     * 
     * @param logClass
     * @param logger
     * @param e
     * @param obj
     */
    public static void error(Class<?> logClass, Logger logger, Throwable e, Object... obj) {
        logger.error(getLogString(logClass.getSimpleName(), "【异常】" + getObjsInfo(obj)), e);
    }

    /**
     * 获取对象信息 输出字符串
     * 
     * @param obj
     * @return
     */
    private static String getObjsInfo(Object[] obj) {
        StringBuffer log = new StringBuffer();
        for (Object o : obj) {
            log.append(o);
        }
        return log.toString();
    }

    /**
     * 
     * 
     * @param obj
     * @return
     */
    private static Object getLogString(Object... obj) {
        StringBuffer log = new StringBuffer();
        for (Object o : obj) {
            log.append(o);
        }
        return log.toString();
    }
}
